package com.xinz.command;

import com.xinz.Constants;
import com.xinz.cache.PlayerCache;
import com.xinz.model.Player;

public abstract class BaseCmd implements Command{
	
	/**
	 * Creates a new instance of BaseCommand.
	 *
	 */
	public BaseCmd() {
		super();
	}

	/**
	 * 执行cmd
	 */
	@Override
	public String execute(String playerId, String[] args) throws Exception {
		
		String result = "";
		// 系统
		if(playerId == Constants.ADMINISTRATOR) {
			result = done(new Player(), args);
		}
		else {
			Player player = PlayerCache.instance.getPlayer(playerId);
				synchronized(player) {
					// 执行
					result = done(player, args);
				}
		}
		return result;
	}

	protected abstract String done(Player player, String[] args) throws Exception;
}
